package com.lelv.framework.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.lelv.framework.bo.IUserBo;
import com.lelv.framework.model.User;
import com.lelv.framework.plugin.Page;

public class UserAction extends BaseAction{

	private IUserBo userBo;
	private Page page = new Page();
	private List<User> userList = new ArrayList<User>();
	private User user = new User();
	private String message = "";

	public String deleteUser(){

		this.userBo.deleteUser(user);

		return SUCCESS;
	}

	public String userZone(){

		this.user = userBo.getUserById(user.getUserId());

		return SUCCESS;
	}

	public String regUser(){

		user.setRegTime(new Date());
		this.userBo.regUser(user);

		return "regOK";
	}

	public String userLogin(){

		Long check = this.userBo.checkLogin(user);
		if(check == -1){
			return "loginError";
		}else{
			User user = this.userBo.getUserById(check);
			this.getSession().setAttribute("userId", user.getUserId());
			this.getSession().setAttribute("userName", user.getUserName());
			return "loginOK";
		}
	}

	public String updateUserMoney(){

		 Double reqMoney = user.getMoney();
		 user = this.userBo.getUserById(user.getUserId());
		 Double updMoney = reqMoney + user.getMoney();
		 user.setMoney(updMoney);
		 this.userBo.updateUser(user);

		return SUCCESS;
	}

	public String updateUserPwd(){

		String newPwd = user.getUserPwd();
		user = this.userBo.getUserById(user.getUserId());
		user.setUserPwd(newPwd);
		this.userBo.updateUser(user);
		this.message = "修改成功";
		return SUCCESS;
	}

	public String getUsers(){

		this.page = userBo.getUsers(page);
		this.userList = page.getList();

		return "getOK";
	}

	public IUserBo getUserBo() {
		return userBo;
	}

	public void setUserBo(IUserBo userBo) {
		this.userBo = userBo;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
